#pragma once
#include <glm/mat4x4.hpp>
#include <glm/gtc/quaternion.hpp>

#include <string>
#include <memory>
#include <vector>

namespace DYGraphics
{
	class Bone
	{
	public:
		glm::mat4x4 mOffsetMat;	// 模型空间到骨骼空间的矩阵
		glm::mat4x4 mLclMat;    // 局部矩阵，变化到父骨骼空间
		glm::mat4x4 mGlobalMat; // 全局矩阵，变换到模型空间

		// 骨骼初始的局部位移，旋转和缩放
		glm::vec3 mLclTranslation;
		glm::vec3 mLclRotation;
		glm::vec3 mLclScaling;
	public:
		Bone() {}

		std::string GetName() const { return mName; }
		int GetIndex() const { return mIndex; }
		Bone* GetParent() const { return mParent; }
		int GetChildCount() const { return mChildren.size(); }
		
		void SetName(const std::string& name) { mName = name; }
		void SetIndex(int index) { mIndex = index; }
		void SetParent(Bone* parent) { mParent = parent; }

		void AddChild(Bone* child)
		{
			if (child == nullptr) return;
			mChildren.push_back(child);
		}

		Bone* GetChild(unsigned int i) const
		{
			if (i < mChildren.size())
			{
				return mChildren[i];
			}

			return nullptr;
		}
	private:
		int mIndex = -1;
		std::string mName;
		Bone* mParent = nullptr;
		std::vector<Bone*> mChildren;
	};
}